package com.zr.lads.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.zr.lads.dao.BaseDao;
import com.zr.lads.dao.FuncDao;
import com.zr.lads.pojo.Func;

/**
 * 功能实现类
 * @author tang
 *
 * @param <T>
 */
@Repository("funcDao")
public class FuncDaoImpl<T> extends BaseDaoImpl<T> implements FuncDao<T> {

	@Resource
	private BaseDao<Object> baseDao;
	
	@Override
	public String getFuncsNameByIds(String ids) {
		StringBuffer hql = new StringBuffer("select f.funcName from Func f where f.funcId in(");
		hql.append(ids);
		hql.append(")");
		List<Object> list = baseDao.find(hql.toString());
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			if (i == 0) {
				sb.append(list.get(i));
			} else {
				sb.append(",");
				sb.append(list.get(i));
			}
		}
		return sb.toString();
	}

	@Override
	public List<Func> getAllFuncs() {
		String hql = "from Func ";
		List<Object> list = baseDao.find(hql);
		List<Func> funcs = new ArrayList<Func>();
		for (int i = 0; i < list.size(); i++) {
			funcs.add((Func)list.get(i));
		}
		return funcs;
	}

}
